package com.ruoyi.statistics.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.statistics.service.ISysStatisticsService;
import com.ruoyi.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 管理或代理商端的数量统计
 */
@RestController
@RequestMapping("/statistics/statisticsDetails")
public class SysStatisticsController extends BaseController {
    @Autowired
    private ISysStatisticsService statisticsService;

    @Autowired
    private ISysDeptService sysDeptService;

    /**
     * 管理或代理商端的数量统计
     * @return
     */
    @GetMapping("/getTotal")
    public AjaxResult getTotal(){
        Long deptId = SecurityUtils.getDeptId();
        SysDept sysDept = sysDeptService.selectDeptById(deptId);
        Map<String,Object> map = new HashMap<>();
        if (sysDept.getType().equals("0")){
            map.put("totalStore",statisticsService.getAllStoreCount());
            map.put("totalStoreChange",statisticsService.getAllStoreCountChange());
            map.put("totalAgent",statisticsService.getAllAgentCount());
            map.put("totalAgentChange",statisticsService.getAllAgentCountChange());
            map.put("totalOrder",statisticsService.getAllOrder());
            map.put("totalOrderChange",statisticsService.getAllOrderChange());
            map.put("totalAmount",statisticsService.getAllAmount());
            map.put("totalAmountChange",statisticsService.getAllAmountChange());
        }
        if (sysDept.getType().equals("1")){
            map.put("totalStore",statisticsService.getAgentStoreCount(deptId));
            map.put("totalStoreChange",statisticsService.getAgentStoreCountChange(deptId));
            map.put("totalOrder",statisticsService.getAgentOrder(deptId));
            map.put("totalOrderChange",statisticsService.getAgentOrderChange(deptId));
            map.put("totalAmount",statisticsService.getAgentAmount(deptId));
            map.put("totalAmountChange",statisticsService.getAgentAmountChange(deptId));
        }
        return AjaxResult.success(map);
    }
    @GetMapping("getType")
    public AjaxResult getType(){
        Long deptId = SecurityUtils.getDeptId();
        SysDept sysDept = sysDeptService.selectDeptById(deptId);
        Map<String,String> map = new HashMap<>();
        map.put("type",sysDept.getType());
        return AjaxResult.success(map);
    }
}
